[Previous] [Next]

The Property Object

The Connection, Recordset, Command, and Field objects expose Properties collections, which contain all the dynamic properties that the ADO provider has added to the built-in properties that are referenced using the standard dot syntax. You can't add dynamic properties yourself; thus, the Properties collection exposes only the Count and Item properties and the Refresh method.

Dynamic properties are important in advanced ADO programming because they often provide supplemental information about an ADO object. Sometimes you can even modify the behavior of a provider by assigning different values to such dynamic properties. Each provider can expose a different set of dynamic properties, even though the OLE DB specifications list a few properties that should have the same meaning across different providers. Here's a routine that fills a ListBox control with the values of all the dynamic properties associated with the object passed as an argument:

Sub ListCustomProperties(obj As Object, lst As ListBox)
    Dim i As Integer, tmp As String
    On Error Resume Next
    lst.Clear
    For i = 0 To obj.Properties.Count - 1
        lst.AddItem obj.Properties(i).Name & " = " & obj.Properties(i)
    Next
End Sub

The Properties collection contains one or more Property objects, which expose four properties: Name, Value, Type, and Attributes. The Type property can be an enumerated value chosen from those listed in Table 13-5. The Attributes property is a bit-field value given by the sum of one or more of the following constants:

Value Description
1-adPropRequired The user must specify a value for this property before the data source is initialized.
2-adPropOptional The user doesn't need to specify a value for this property before the data source is initialized.
512-adPropRead The user can read the property.
1024-adPropWrite The user can assign a value to the property.

If the Attributes property returns the value 0-adPropNotSupported, it means that the provider doesn't support this property.